package com.oms.app.order.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.oms.app.order.dao.IOrderDAO;
import com.oms.app.order.model.Order;
import com.oms.core.dao.impl.GeneralDAO;

/**
 * @author Loong_Mit
 * @date Sep 1, 2012 6:32:12 PM
 */

public class OrderDAOImpl extends GeneralDAO<Order, String> implements IOrderDAO {

	public List<Order> getOrderList(HttpServletRequest request) {
		return this.queryForList("getOrderByShopId", request.getAttribute("shopId"));
	}
	
	public boolean auditOrder(String orderIds, String status) {
		try {
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("orderIds", orderIds);
			param.put("status", status);
			this.update("auditOrder", param);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	public boolean deleteOrder(String PK) {
		try {
			this.delete("delete", PK);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	public List<Map<String, Object>> getOrderDetailList(String orderId) {
		return this.getList("getOrderDetails", orderId);
	}
	
	public boolean changeDetailStatus(String detailId, String status) {
		try {
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("id", detailId);
			param.put("status", status);
			this.update("changeDetailStatus", param);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	public boolean delDetailsByOrderId(String orderId) {
		try {
			this.delete("delDetailsByOrderId", orderId);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	public boolean delOrderDetailsByPK(String PK) {
		try {
			this.delete("delOrderDetailsByPK", PK);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
}